﻿using App.Configuration;
using System.Collections.Generic;
using System.Linq;

namespace App.EntityFramework.Seed
{
    internal class DefaultButtonsCreator
    {
        private readonly WebPlusDbContext _context;

        public DefaultButtonsCreator(WebPlusDbContext _context)
        {
            this._context = _context;
        }

        internal void Create()
        {
            var buttons = new List<Button> {
                new Button {
                     ButtonName="添加",
                     ButtonLink="add",
                     IconCls="fa-plus"
                },
                new Button {
                     ButtonName="修改",
                     ButtonLink="edit",
                     IconCls="fa-edit"
                },
                new Button {
                     ButtonName="新增",
                     ButtonLink="insert",
                     IconCls="fa-plus"
                },
                new Button {
                     ButtonName="撤销",
                     ButtonLink="undo",
                     IconCls="fa-undo"
                },
                new Button {
                     ButtonName="保存",
                     ButtonLink="save",
                     IconCls="fa-save"
                },
                new Button {
                     ButtonName="删除",
                     ButtonLink="del",
                     IconCls="fa-remove"
                }
            };

            buttons.ForEach(delegate (Button button) {
                if (!_context.Button.Any(s => s.ButtonName == button.ButtonName))
                {
                    _context.Button.Add(button);
                }
            });

            _context.SaveChanges();
        }
    }
}